﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using AbstraX.ClientInterfaces;
using System.Reflection;
using AbstraX.XPathBuilder;
using System.Linq;
using MvvmTreeView;
using AbstraX;
using AbstraX.Contracts;

namespace TreeBuilderTest.Entities
{
    public class BaseMethodOperation : IOperation
    {
        private MethodInfo method;
        public event ChildrenLoadedHandler ChildrenLoaded;
        private IBase parent;
        private string name;
        private string queryWhereProperty;
        private object queryWhereValue;

       public  IAbstraXExtension LoadExtension(IBase baseObject, ITreeNode treeNode)
        {
            return null;
        }
      
       

        public BaseMethodOperation(MethodInfo method, IBase parent)
        {
            this.method = method;
            this.parent = parent;
        }

        public MethodInfo Method
        {
            get 
            { 
                return method; 
            }
            
            set
            { 
                method = value; 
            }
        }

        public OperationDirection Direction
        {
            get 
            {
                return OperationDirection.Incoming;
            }
        }

        public void LoadChildren()
        {
            throw new NotImplementedException();
        }

        public System.Collections.Generic.IEnumerable<IElement> ChildElements
        {
            get { throw new NotImplementedException(); }
        }

        public string ID
        {
            get 
            {
                return this.MakeID("Method='" + method.Name + "'");
            }
        }

        public string ParentID
        {
            get { throw new NotImplementedException(); }
        }

        public string Name
        {
            get 
            {
                if (name == null)
                {
                    name = this.GenerateName();
                }

                return name;
            }
        }

        public string DesignComments
        {
            get { throw new NotImplementedException(); }
        }

        public string Documentation
        {
            get { throw new NotImplementedException(); }
        }

        public bool HasDocumentation
        {
            get { throw new NotImplementedException(); }
            set { throw new NotImplementedException(); }
        }

        public string DocumentationSummary
        {
            get { throw new NotImplementedException(); }
            set { throw new NotImplementedException(); }
        }

        public string ImageURL
        {
            get { throw new NotImplementedException(); }
        }

        public IBase Parent
        {
            get
            {
                return parent;
            }
        }

        public string FolderKeyPair
        {
            get { throw new NotImplementedException(); }
        }

        public System.ServiceModel.DomainServices.Client.DomainContext Context
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public IQueryable ExecuteWhere(string property, object value)
        {
            queryWhereProperty = property;
            queryWhereValue = value;

            return this.ChildElements.AsQueryable();
        }

        public IQueryable ExecuteWhere(System.Linq.Expressions.Expression expression)
        {
            throw new NotImplementedException();
        }

        public IQueryable ExecuteWhere(XPathAxisElement element)
        {
            throw new NotImplementedException();
        }

        public IQueryable ExecuteWhere(XPathAxisElement element, XPathAxisElement childrenElement)
        {
            var predicate = childrenElement.Predicates.First();

            queryWhereProperty = predicate.Left;
            queryWhereValue = predicate.Right;

            return this.ChildElements.AsQueryable();
        }

        public void ClearPredicates()
        {
            queryWhereProperty = null;
            queryWhereValue = null;
        }

        public bool IsConstructor
        {
            get
            {
                return false;
            }
        }


        public DefinitionKind Kind
        {
            get { throw new NotImplementedException(); }
        }


        public bool HasChildren
        {
            get { throw new NotImplementedException(); }
        }


        public string DebugInfo
        {
            get { throw new NotImplementedException(); }
        }


        public float ChildOrdinal
        {
            get { throw new NotImplementedException(); }
        }


        public IRoot Root
        {
            get { throw new NotImplementedException(); }
        }


        public Modifiers Modifiers
        {
            get { throw new NotImplementedException(); }
        }


        public bool IsChildrenLoaded
        {
            get { throw new NotImplementedException(); }
        }


        public IAbstraXExtension LoadExtension(IBase baseObject)
        {
            throw new NotImplementedException();
        }

        public void AddView(Hydra.Shell.Interfaces.IDocumentView view)
        {
            throw new NotImplementedException();
        }

        public void CloseView(Hydra.Shell.Interfaces.IDocumentView view)
        {
            throw new NotImplementedException();
        }

        public void CloseAllViews()
        {
            throw new NotImplementedException();
        }

        public void UpdateAllViews()
        {
            throw new NotImplementedException();
        }
    }
}
